<script setup>
import { newRandomUid } from "@/utils";

const props = defineProps({
  config: {
    type: Object,
    required: true,
  },
  name: {
    type: String,
    default: "",
  },
  disabled: {
    type: Boolean,
    default: false,
  },
  info: {
    type: Object,
  },
});

const emits = defineEmits(["update:config", "change", "append"]);

const form = ref({
  $show: false,
  $mode: "popup",
  $removeable: true,
});

const detail = computed({
  get: () => {
    return Object.assign({}, form.value, props.config);
  },
  set: (val) => {
    emits("update:config", val);
    emits("change", val);
  },
});

const initConfig = () => {
  if (!props.info.children || props.info.children.length == 0) {
    emits("append", {
      uid: newRandomUid(),
      type: "BasicPopup",
      name: "弹窗背景",
      pageConfig: {},
    });
    emits("append", {
      uid: newRandomUid(),
      type: "BButton",
      name: "关闭按钮",
      pageConfig: {
        $position: { top: 537, left: 180 },
        img: "./imagesStatic/activity/close_icon.png",
        $size: { width: 30, height: 30 },
        linkType: "system",
        type: "closePopup",
      },
    });
  }
};

const onChange = (val) => {
  detail.value = detail.value;
};

onMounted(() => {
  onChange();
  nextTick(() => {
    initConfig();
  });
});
</script>
<template>
  <el-form :model="detail" label-width="auto" :disabled="disabled"> </el-form>
</template>
